package com.tang;

import com.tang.pojo.AuthInfo;
import com.tang.service.AuthService;

import java.text.ParseException;
import java.time.LocalDateTime;

/**
 * 模拟一坨坨代码实现审核
 *
 * @author fulin.tang
 * @version V3.0
 * @since 2021/9/30 18:01
 */
public class AuthController {

    /**
     * 审批状态查询
     *
     * @param uId      userId
     * @param orderId  订单id
     * @param authDate 日期
     * @return 权限信息
     * @throws ParseException 日期转换异常
     */
    public AuthInfo doAuth(String uId, String orderId, LocalDateTime authDate) throws ParseException {
        // 三级审批
        LocalDateTime date = AuthService.queryAuthInfo("1000013", orderId);
        if (null == date) return new AuthInfo("0001", "单号：", orderId, "状态：待三次审批负责人 ", "韩总");

        // 二级审批
        if (authDate.isAfter(LocalDateTime.parse("2021-06-01T00:00:00"))
                && authDate.isBefore(LocalDateTime.parse("2021-06-25T23:59:59"))) {
            date = AuthService.queryAuthInfo("1000012", orderId);
            if (null == date) return new AuthInfo("0001", "单号：", orderId, "状态：待二级审批负责人", "曾总");
        }

        // 一级审批
        if (authDate.isAfter(LocalDateTime.parse("2021-06-11T00:00:00"))
                && authDate.isBefore(LocalDateTime.parse("2021-06-20T23:59:59"))) {
            date = AuthService.queryAuthInfo("1000011", orderId);
            if (null == date) return new AuthInfo("0001", "单号：", orderId, "状态：待一级审批负责人", "王总");
        }

        return new AuthInfo("0001", "单号：", orderId, "状态：审批完成");
    }

}
